import Cookies from 'js-cookie'

import headLogo from '@/assets/images/head-logo.png'

export default {
    state() {
        return {
            sidebar: {
              opened: !+Cookies.get('sidebarStatus'),
              withoutAnimation: false
            },
            device: 'desktop',
            headLogo: headLogo,
            menuOpends: ['/sys'],
            defaultMenu: '/sys/namespace',
            menus: [
                {
                  path: '/sys', id:'1', name: 'sysMan', meta: {title: '网关管理', icon: 'el-icon-s-tools'}, 
                  children: [
                    {
                       id:'2', path: '/sys/namespace', name: 'namespace', meta: {title: '命名空间', icon: 'el-icon-s-grid'}
                    },
                    {
                       id:'3', path: '/sys/router', name: 'router', meta: {title: '路由管理', icon: 'el-icon-collection'}
                    },
                    {
                       id: '5', path: '/sys/user', name: 'user', meta: {title: '用户管理', icon: 'el-icon-user-solid'}
                    }
                  ]
                }
            ]
        }
    },

    mutations: {
      TOGGLE_SIDEBAR: state => {
        if (state.sidebar.opened) {
          Cookies.set('sidebarStatus', 1)
        } else {
          Cookies.set('sidebarStatus', 0)
        }
        state.sidebar.opened = !state.sidebar.opened
      },
      CLOSE_SIDEBAR: (state, withoutAnimation) => {
        Cookies.set('sidebarStatus', 1)
        state.sidebar.opened = false
        state.sidebar.withoutAnimation = withoutAnimation
      },
      TOGGLE_DEVICE: (state, device) => {
        state.device = device
      },
      setDefaultMenu(state, name) {
        state.defaultMenu = name
      }
    },
    
    actions: {
      ToggleSideBar: ({ commit }) => {
        commit('TOGGLE_SIDEBAR')
      },
      CloseSideBar({ commit }, { withoutAnimation }) {
        commit('CLOSE_SIDEBAR', withoutAnimation)
      },
      ToggleDevice({ commit }, device) {
        commit('TOGGLE_DEVICE', device)
      }
    }

}
